package com.itheima.cases;

import java.util.Random;
import java.util.Scanner;

public class TextDemo2 {
    public static void main(String[] args) {
        Scanner rs = new Scanner(System.in);
        System.out.println("请输入生成随机验证码的位数：");
        int insert = rs.nextInt();
        System.out.println(createCode(insert));
    }
    public static String createCode(int n) {
        Random rd = new Random();
        String code = "";
        for (int i = 1; i <= n; i++) {
            int type = rd.nextInt(3);
            switch (type) {
                case 0:
                    //随机数字
                    code += rd.nextInt(10);
                    break;
                case 1:
                    //随机大写字母
                    char ch1 = (char) (rd.nextInt(26) + 65);
                    code += ch1;
                    break;
                case 2:
                    //随机小写字母
                    char ch2 = (char) (rd.nextInt(26) + 97);
                    code += ch2;
                    break;
            }
        }
        return code;
    }
}
